package com.axt.dbaudit.bean.cfg;

import java.util.List;

import com.axt.dbaudit.base.MsgFuncExt;
import com.axt.dbaudit.model.cfg.IpGroup;
import com.axt.soa.bean.BaseFuncBean;
import com.axt.soa.msg.types.MsgParam;
import com.axt.util.DateTime;

public class IpGroupBean extends BaseFuncBean {
	/**
	 * 添加客户端分组
	 * 
	 * @param aGroupName
	 * @return
	 */
	public int addGroupName(String serverPath, String groupName) {
		prepare(serverPath);

		request.addParam(MsgParam.MSG_COL_AU_NAME, groupName);

		return execute(MsgFuncExt.FUNC_ADD_IP_GROUP, CONN_T_TCP);
	}

	/**
	 * 添加客户端IP
	 * 
	 * @param aGroupau_comname
	 * @param aGroupau_mac
	 * @param aGroupuser_id
	 * @param aGroupau_IP
	 * @return
	 */
	public int addClientIp(String serverPath, String groupau_comname,
			String groupau_mac, int group_id, String iP, String ipName) {
		prepare(serverPath);

		request.addParam(MsgParam.MSG_COL_AU_COMNAME, groupau_comname);
		request.addParam(MsgParam.MSG_COL_AU_MAC, groupau_mac);
		request.addParam(MsgParam.MSG_COL_AU_GROUP_ID, group_id);
		request.addParam(MsgParam.MSG_COL_AU_IP, iP);
		request.addParam(MsgParam.MSG_COL_AU_IPNAME, ipName);
		// request.addParam(MsgParam.MSG_COL_AU_CREATETIME,DateTime.getNowDate().toString());
		request.addParam(MsgParam.MSG_COL_AU_MODIFYTIME, DateTime.getStrDate());

		return execute(MsgFuncExt.FUNC_ADD_IP_CLIENT, CONN_T_TCP);
	}

	/**
	 * 删除客户端分组
	 * 
	 * @param aIdList
	 * @return
	 */
	public int deleteGroupById(String serverPath, int groupId) {
		prepare(serverPath);
		
		request.addParam(MsgParam.MSG_COL_AU_ID, groupId);

		return execute(MsgFuncExt.FUNC_DELETE_IP_GROUP, CONN_T_TCP);
	}

	/**
	 * 删除客户端IP
	 * 
	 * @param aIdList
	 *            (用','分隔的列表)
	 * @return
	 */
	public int deleteClientIpById(String serverPath, int au_id) {
		prepare(serverPath);
		
		request.addParam(MsgParam.MSG_COL_AU_ID, au_id);

		return execute(MsgFuncExt.FUNC_DELETE_IP_GROUP, CONN_T_TCP);
	}

	/**
	 * 重命名组
	 * 
	 * @param aGroup_Name
	 * @param aGroup_ID
	 * @return
	 */
	public int modifyGroupName(String serverPath, String group_Name, int group_ID) {
		prepare(serverPath);
		
		request.addParam(MsgParam.MSG_COL_AU_NAME, group_Name);
		request.addParam(MsgParam.MSG_COL_AU_ID, group_ID);

		return execute(MsgFuncExt.FUNC_MODIFY_IP_GROUP, CONN_T_TCP);
	}

	/**
	 * 修改客户端IP
	 * 
	 * @param acomname
	 * @param amac
	 * @param aIP
	 * @param aID
	 * @return
	 */
	public int modifyClientIP(String serverPath, String comname, String mac, String iP, int iD) {
		prepare(serverPath);
		
		request.addParam(MsgParam.MSG_COL_AU_COMNAME, comname);
		request.addParam(MsgParam.MSG_COL_AU_MAC, mac);
		request.addParam(MsgParam.MSG_COL_AU_IP, iP);
		request.addParam(MsgParam.MSG_COL_AU_ID, iD);
		request.addParam(MsgParam.MSG_COL_AU_MODIFYTIME, DateTime.getStrDate());
		return execute(MsgFuncExt.FUNC_MODIFY_IP_CLIENT, CONN_T_TCP);
	}

	/**
	 * 获取IP_group和item列表
	 */
	public List<IpGroup> queryIpGroupAndItem(String serverPath) {
		prepare(serverPath);
		
		return fetch(MsgFuncExt.FUNC_QUERY_IP_GROUP_ITEM,
				"com.axt.dbaudit.model.IpGroup", "IpGroup", CONN_T_TCP);
	}
}
